import {CounterImpl} from './counter';

class MyCounter{
    pEle:HTMLParamElement;
    counter: CounterImpl;
    constructor(pEle:HTMLParamElement){
        this.pEle=pEle;
        this.counter = new CounterImpl();
    }

    inc(){
        this.counter.inc();
        this.refresh();
    }
    dec(){
        this.counter.dec();
        this.refresh();
    }

    refresh(){
        this.pEle.innerText = this.counter.currentCounter();
    }
}

window.onload = function() {
    const pEle = <HTMLParamElement>document.getElementById('counter');
    const myCounter = new MyCounter(pEle);
    const buttons = document.getElementsByTagName('input');
    buttons[0].addEventListener('click',function(evt){
              myCounter.inc();
    });
    buttons[1].addEventListener('click',function(){
        myCounter.dec();
});
}
